//
//  WSPayTypeSectionHeaderView.m
//  FD
//
//  Created by xiaofang wang on 2018/11/6.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "WSPayTypeSectionHeaderView.h"
@interface WSPayTypeSectionHeaderOne()
/**背景*/
@property (nonatomic, strong) UIView *bgView;
/**1.到点支付lb*/
@property (nonatomic, strong) UILabel *daodianZiFuLb;
/**按钮*/
@property (nonatomic, strong) UIButton *btn;

@end
@implementation WSPayTypeSectionHeaderOne

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)setupView {
    self.contentView.backgroundColor = kMainLightGrayColor; //灰色背景，留出1px当做线

    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.daodianZiFuLb];
    [self.bgView addSubview:self.btn];
}
//!!!!:layout
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-1);
    }];
    
    [self.daodianZiFuLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(15);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100, 22));
    }];
    
    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bgView.mas_right).offset(-10);
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.centerY.equalTo(self.bgView.mas_centerY);
    }];
}


- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}
- (UILabel *)daodianZiFuLb {
    if (!_daodianZiFuLb) {
        _daodianZiFuLb = [UILabel new];
        _daodianZiFuLb.text = NSLocalizedString(L_Pay_Offline, @"线下支付");
    }
    return _daodianZiFuLb;
}
- (UIButton *)btn {
    if (!_btn) {
        _btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_btn addTarget:self action:@selector(clickDaoDianZiFuBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [_btn setImage:[UIImage imageNamed:@"unselected"] forState:(UIControlStateNormal)];
        [_btn setImage:[UIImage imageNamed:@"selected"] forState:(UIControlStateSelected)];
    }
    return _btn;
}
- (void)clickDaoDianZiFuBtnAction:(UIButton *)btn {
    FDLog(@"点击到店支付");
    
    btn.selected = !btn.selected;
    if (self.clickSelectDaoDianZhiFuBtnBlock) {
        self.clickSelectDaoDianZhiFuBtnBlock();
    }
}

@end
#pragma mark - =========分割线==========

@interface WSPayTypeSectionHeaderView()
/**背景*/
@property (nonatomic, strong) UIView *bgView;

/**nameLb*/
@property (nonatomic, strong) UILabel *nameLb;
/**按钮*/
@property (nonatomic, strong) UIButton *btn;
/**箭头*/
//@property (nonatomic, strong) UIImageView *arrowIv;
/**箭头lb*/
@property (nonatomic, strong) UILabel *arrowLb;

@end

@implementation WSPayTypeSectionHeaderView
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView
{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.nameLb];
    [self.bgView addSubview:self.btn];
    [self.bgView addSubview:self.arrowLb]; //文字箭头 >  v
}

//!!!!:layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView).offset(15);
        make.size.mas_equalTo(CGSizeMake(100, 24));
        make.centerY.equalTo(self.bgView.mas_centerY);
    }];
    
    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.arrowLb.mas_left);
        make.size.mas_equalTo(CGSizeMake(120, 22));
        make.centerY.equalTo(self.bgView.mas_centerY);
    }];
    
    [self.arrowLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bgView.mas_right).offset(-10);
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.centerY.equalTo(self.bgView.mas_centerY);
    }];
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        _nameLb.text = @"银行卡";
    }
    return _nameLb;
}


- (UIButton *)btn {
    if (!_btn) {
        _btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_btn setTitle:@"请选择银行卡" forState:(UIControlStateNormal)];
        [_btn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        
//        [_btn setImage:[UIImage imageNamed:@""] forState:(UIControlStateNormal)];
        [_btn addTarget:self action:@selector(clickSelectBankBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _btn;
}
- (UILabel *)arrowLb {
    if (!_arrowLb) {
        _arrowLb = [[UILabel alloc] init];
        _arrowLb.textColor = [UIColor lightGrayColor];
        _arrowLb.text = @">";
    }
    return _arrowLb;
}

- (void)clickSelectBankBtnAction:(UIButton *)btn
{
    btn.selected = !btn.selected;
    
    FDLog(@"按钮选中状态: %d",btn.selected);
    
    if (self.clickSelectBankBtnBlock) {
        self.clickSelectBankBtnBlock(self.arrowLb, btn);
    }
}

@end
